//
//  ClassDetailViewController.m
//  EducationAdminClient
//
//  Created by xuyingwei on 16/8/23.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "ClassDetailViewController.h"
#import "ListDetailCell.h"
#import "KeyValuesClass.h"
@interface ClassDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *myTableView;
    BOOL        _isHaveClassNumber;//是否有班号 ---yes表示有
    NSInteger   _count;//章节内容行数
    NSMutableArray *_needMutArr;//章节内容数组
}
@end
@implementation ClassDetailViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.cusTabView.hidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
    self.cusTabView.userInteractionEnabled = NO;
}
-(void)viewDidLoad{
    [super viewDidLoad];
    _needMutArr = [[NSMutableArray alloc] init];
//    BOOL isBetweenTime = [self isBetweenFromHour:19 toHour:24];
//    NSLog(@"isbetweentime = %d",isBetweenTime);
    _testLessionPlanString = @"1. 学习教室常用物品 backpack背包,book 书,chair 椅子,crayon 蜡笔,desk 书桌,eraser橡皮,marker 马克笔,pen 钢笔,pencil 铅笔,ruler尺子。 #2. 学习常见颜色 blue 蓝色,red 红色,green 绿色,yellow 黄色。 #3. 学习日常打招呼用语。 #4. 学唱单元主题歌曲 The Classroom Song。";
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self createLeftNavBar];
//    myTableView.backgroundView.backgroundColor = [UIColor redColor];
    //self.ClassDetailArr = [self.model.name componentsSeparatedByString:@","];
//    self.view.backgroundColor = [UIColor redColor];
    self.tbView =[[UITableView alloc]init];
    self.tbView.separatorStyle = NO;
    [self.view addSubview:self.tbView];
    self.tbView.delegate = self;
    self.tbView.dataSource = self;
    [self.tbView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.view.mas_top);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    [self setTitleLabelText:@"课程详情"];

    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    float lastHeight;
    UILabel *la =[[UILabel alloc]init];
    la.numberOfLines = 0;
    
    //这里添加了角色判断   汉普森特殊处理，不需要修改
    if ([getUserType() isEqualToString:UserISHPSTeacher]) {
//        if (indexPath.row<3) {
//            
//        }
        if(indexPath.row==0){
            la.text = self.ClassDetailArr[indexPath.row];
            float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
            if(hh>25){
                lastHeight = hh+20;
            }else{
                lastHeight =  110/2;
            }
        }
        
        if(indexPath.row == 1){
            
            NSLog(@"%i",_isHaveClassNumber?4:5);
            
            if (_model.CHAPTER_NAME) {
                NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节: %@",_model.CHAPTER_NAME];
                la.text = firstStr;
                float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
                if(hh>25){
                    lastHeight = hh+20;
                }else{
                    lastHeight =  110/2;
                }
                
            }else{
                lastHeight =  110/2;
            }
            
        }else if (indexPath.row == 3){
            if (_model.CHAPTER_DESCRIBE) {
                NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节: %@",_model.CHAPTER_DESCRIBE];
                la.text = firstStr;
                float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
                if(hh>25){
                    lastHeight = hh+20;
                }else{
                    lastHeight =  110/2;
                }
                
            }else{
//                NSMutableString *firstStr = [NSMutableString stringWithFormat:@"%@",_testLessionPlanString];
//                
//                
//                NSMutableArray * arr = [self componentsAllSeparatedByStringAndReturnAMutbleArr:_testLessionPlanString andString:@"#"];
//                NSString *str = @"章节内容：";
//                for (int i = 0;i<arr.count ;i++) {
//                    //                        if (i == arr.count-1) {
//                    //                            str = [NSString stringWithFormat:@"%@%@",str,[arr objectAtIndex:i]];
//                    //                        }else{
//                    str = [NSString stringWithFormat:@"%@\n%@",str,[arr objectAtIndex:i]];
//                    //                        }
//                    //                    cell.textLabel.text = str;
//                    
//                }
//                
//                //                for (NSString *str in _needMutArr) {
//                //                    la.text = str;
//                //                    hh += [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;
//                //                }
//                //
//                
//                
//                la.text = str;
//                float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;;//动态计算高度
//                if(hh>25){
//                    lastHeight = hh+20+20;
//                }else{
//                    lastHeight =  110/2;
//                }
//                CGRect frame = la.bounds;
//                NSLog(@"%@",NSStringFromCGSize(frame.size));
                                lastHeight =  110/2;
            }
        }else if (indexPath.row == 2){
            if (_model.CHAPTER_TASK) {
                NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节: %@",_model.CHAPTER_TASK];
                la.text = firstStr;
                float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
                if(hh>25){
                    lastHeight = hh+20;
                }else{
                    lastHeight = 110/2;
                }
                
            }else{
                lastHeight =  110/2;
            }
        }else{
            lastHeight = 110/2;
        }

    }else{
        if(indexPath.row==0||indexPath.row==1){
            la.text = self.ClassDetailArr[indexPath.row];
            float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
            if(hh>25){
                lastHeight = hh+20;
            }else{
                lastHeight =  110/2;
            }
        }
        
        if(indexPath.row == 2){
            
            NSLog(@"%i",_isHaveClassNumber?4:5);
    
            if (_model.CHAPTER_NAME) {
                NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节: %@",_model.CHAPTER_NAME];
                la.text = firstStr;
                float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
                if(hh>25){
                    lastHeight = hh+20;
                }else{
                    lastHeight =  110/2;
                }
    
            }else{
                lastHeight =  110/2;
            }
    
        }else if (indexPath.row == 4){
            if (_model.CHAPTER_DESCRIBE) {
                NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节: %@",_model.CHAPTER_DESCRIBE];
                la.text = firstStr;
                float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
                if(hh>25){
                    lastHeight = hh+20;
                }else{
                    lastHeight =  110/2;
                }
    
            }else{
//                NSMutableString *firstStr = [NSMutableString stringWithFormat:@"%@",_testLessionPlanString];
//                
//                
//                NSMutableArray * arr = [self componentsAllSeparatedByStringAndReturnAMutbleArr:_testLessionPlanString andString:@"#"];
//                NSString *str = @"章节内容：";
//                for (int i = 0;i<arr.count ;i++) {
//                    //                        if (i == arr.count-1) {
//                    //                            str = [NSString stringWithFormat:@"%@%@",str,[arr objectAtIndex:i]];
//                    //                        }else{
//                    str = [NSString stringWithFormat:@"%@\n%@",str,[arr objectAtIndex:i]];
//                    //                        }
////                    cell.textLabel.text = str;
//                    
//                }
//                
////                for (NSString *str in _needMutArr) {
////                    la.text = str;
////                    hh += [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;
////                }
////
//                
//                
//                la.text = str;
//                float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;;//动态计算高度
//                if(hh>25){
//                    lastHeight = hh+20+20;
//                }else{
//                    lastHeight =  110/2;
//                }
//                CGRect frame = la.bounds;
//                NSLog(@"%@",NSStringFromCGSize(frame.size));
                lastHeight =  110/2;
            }
        }else if (indexPath.row == 3){
            if (_model.CHAPTER_TASK) {
                NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节: %@",_model.CHAPTER_TASK];
                la.text = firstStr;
                float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
                if(hh>25){
                    lastHeight = hh+20;
                }else{
                    lastHeight = 110/2;
                }
                
            }else{
                lastHeight =  110/2;
            }
        }else{
            lastHeight = 110/2;
        }
        
    }

    
//    if(indexPath.row==0||indexPath.row==1||indexPath.row==2){
//        la.text = self.ClassDetailArr[indexPath.row];
//        float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
//        if(hh>25){
//            lastHeight = hh+20;
//        }else{
//            lastHeight =  110/2;
//        }
//    }else if (indexPath.row==5){
//        
//        NSLog(@"%i",_isHaveClassNumber?4:5);
//        
//        if (_model.CHAPTER_NAME) {
//            NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节: %@",_model.CHAPTER_NAME];
//            la.text = firstStr;
//            float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
//            if(hh>25){
//                lastHeight = hh+20;
//            }else{
//                lastHeight =  110/2;
//            }
//            
//        }else{
//            lastHeight =  110/2;
//        }
//        
//    }else if (indexPath.row==_isHaveClassNumber?5:6){
//        if (_model.CHAPTER_DESCRIBE) {
//            NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节: %@",_model.CHAPTER_DESCRIBE];
//            la.text = firstStr;
//            float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
//            if(hh>25){
//                lastHeight = hh+20;
//            }else{
//                lastHeight =  110/2;
//            }
//            
//        }else{
//            lastHeight =  110/2;
//        }
//    }else if (indexPath.row==_isHaveClassNumber?6:7){
//        if (_model.CHAPTER_TASK) {
//            NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节: %@",_model.CHAPTER_TASK];
//            la.text = firstStr;
//            float hh = [la sizeThatFits:CGSizeMake(KWIDTH-60, CGFLOAT_MAX)].height;//动态计算高度
//            if(hh>25){
//                lastHeight = hh+20;
//            }else{
//                lastHeight = 110/2;
//            }
//            
//        }else{
//            lastHeight =  110/2;
//        }
//    }else{
//        lastHeight = 110/2;
//    }
    
    return lastHeight;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    return self.dataArr.count;
//    if (_ModelArr.count>0) {
//        return _ModelArr.count;
//    }else{
//        return 1;
//    }
    
    NSLog(@"%zd",self.ClassDetailArr.count);
    //这里添加了角色判断   改过了
    if ([getUserType() isEqualToString:UserISHPSTeacher]) {
        
//        return 5;
//        NSLog(@"%@",_ClassDetailArr);
//        int i = 0;
        for (int i = 0;i<_ClassDetailArr.count; i++) {
            NSString *str = [_ClassDetailArr objectAtIndex:i];
            NSRange range = [str rangeOfString:@"班号"];
            if (range.location != NSNotFound) {
                //                [_ClassDetailArr removeObjectAtIndex:i];
                _isHaveClassNumber = YES;
                break;
            }
        }
        return _ClassDetailArr.count;
//        if (_isHaveClassNumber) {
//            //            [_ClassDetailArr removeObjectAtIndex:i];
//            return 5;
//        }else{
//            return 5;
//        }
    }else{
//        NSLog(@"%@",_ClassDetailArr);
//        int i = 0;
//        for (;i<_ClassDetailArr.count; i++) {
//            NSString *str = [_ClassDetailArr objectAtIndex:i];
//            NSRange range = [str rangeOfString:@"班号"];
//            if (range.location != NSNotFound) {
////                [_ClassDetailArr removeObjectAtIndex:i];
//                _isHaveClassNumber = YES;
//                break;
//            }
//        }
//        if (_isHaveClassNumber) {
////            [_ClassDetailArr removeObjectAtIndex:i];
//            return 5;
//        }else{
//            return 5;
//        }
        
        
        
        return 5;
    }

//    return 8;
}
-(NSArray *)ClassDetailArr{
    if (!_ClassDetailArr) {
        _ClassDetailArr = [NSMutableArray arrayWithArray:[self.model.name componentsSeparatedByString:@","]];
        
    }
    return _ClassDetailArr;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier = @"classDetialCellID";
    ListDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[ListDetailCell alloc] initWithReuseIdentifier:identifier];
//        [cell initWithReuseIdentifier:identifier];
        
    }
    NSString *NoInformationStr;//暂无信息
    NSString *NoStr;//暂无
    //这里添加功能判断
    if (getEnglishLanguage()) {
        NoStr = @"Not available";
        NoInformationStr = @"No Information";
    }else{
        NoStr = @"暂无";
        NoInformationStr = @"暂无信息";
    }

    
    cell.title.hidden = YES;
    cell.titleLabel.hidden = YES;
    [cell setEditIs:NO];
    cell.userInteractionEnabled = NO;
    //这里添加了角色判断   改过了
    if ([getUserType() isEqualToString:UserISHPSTeacher]) {
//        if (indexPath.row == 0){
//            if (_isHaveClassNumber) {
//                if (_ClassDetailArr.count != 0) {
//                    NSMutableString *firstStr = [NSMutableString stringWithFormat:@"%@",_ClassDetailArr.firstObject];
//                    NSRange range1 = [firstStr rangeOfString:@"_"];
//                    //            NSRange range2 = [firstStr rangeOfString:@":"];
//                    if (range1.location!=NSNotFound) {
//                        [firstStr replaceCharactersInRange:range1 withString:@"："];
//                    }
//                    NSLog(@"%@",firstStr);
//                    NSRange range2 = [firstStr rangeOfString:@"课程"];
//                    [firstStr replaceCharactersInRange:range2 withString:@"Class"];
//                    cell.textLabel.text = firstStr;
//                }else{
////                    cell.textLabel.text = @"课程：暂无";
//                    //这里添加功能判断
//                    if (getEnglishLanguage()) {
//                        cell.textLabel.text = @"Class：";
//                    }else{
//                        cell.textLabel.text = @"课程：";
//                    }
//                    
//                }
//
//            }else{
//                if (_ClassDetailArr.count>1) {
//                    NSMutableString *firstStr = [NSMutableString stringWithFormat:@"%@",[_ClassDetailArr objectAtIndex:1]];
//                    NSRange range1 = [firstStr rangeOfString:@":"];
//                    //            NSRange range2 = [firstStr rangeOfString:@":"];
//                    if (range1.location!=NSNotFound) {
//                        [firstStr replaceCharactersInRange:range1 withString:@"："];
//                        NSRange range2 = [firstStr rangeOfString:@"_"];
//                        if (range2.location!=NSNotFound) {
//                            [firstStr replaceCharactersInRange:range2 withString:@"："];
//                        }
//                        NSLog(@"%@",firstStr);
//                    }
//                    NSRange range2 = [firstStr rangeOfString:@"学员"];
//                    //这里添加功能判断
//                    if (getEnglishLanguage()) {
//                        [firstStr replaceCharactersInRange:range2 withString:@"Student"];
//                    }else{
//                        
//                    }
//                    
//                    cell.textLabel.text = firstStr;
//                    //这里添加了角色判断   改过了
//                    if ([getUserType() isEqualToString:UserISHPSTeacher]) {
//                        if (_model.ENGLISH_NAME) {
//                            //这里添加功能判断
//                            if (getEnglishLanguage()) {
//                                cell.textLabel.text = [NSString stringWithFormat:@"Student：%@",_model.ENGLISH_NAME];
//                            }else{
//                                
//                            }
//                            
//                        }
//                    }else{
//                        
//                    }
//
//                    
//                }else{
//                    //这里添加功能判断
//                    if (getEnglishLanguage()) {
//                        cell.textLabel.text = [NSString stringWithFormat:@"Student：%@",NoStr];
//                    }else{
//                        cell.textLabel.text = [NSString stringWithFormat:@"学员：%@",NoStr];
//                    }
//                    
//                }
//
//            }
//            
//            
//            
//            
//
//            
//            NSLog(@"%@",_ClassDetailArr);
//            
//            //        cell.textLabel.text = self.model.startTime;
//        }
//        if (indexPath.row == 1) {
//            if (_model.CHAPTER_NAME) {
//                //这里添加功能判断
//                NSMutableString *firstStr;
//                if (getEnglishLanguage()) {
//                    firstStr = [NSMutableString stringWithFormat:@"Chapter：%@",_model.CHAPTER_NAME];
//                }else{
//                    firstStr = [NSMutableString stringWithFormat:@"章节：%@",_model.CHAPTER_NAME];
//                }
//                
//                
//                NSLog(@"%@",firstStr);
//                cell.textLabel.text = firstStr;
//            }else{
//                //这里添加功能判断
//                if (getEnglishLanguage()) {
//                    cell.textLabel.text = [NSString stringWithFormat:@"Chapter：%@",NoStr];
//                }else{
//                    cell.textLabel.text = [NSString stringWithFormat:@"章节：%@",NoStr];
//                }
//                
//            }
//        }
//        if (indexPath.row == 3) {//章节内容
//            cell.textLabel.numberOfLines = 0;
//            cell.textLabel.lineBreakMode = NSLineBreakByCharWrapping;
//            if (_model.CHAPTER_DESCRIBE) {
//                //这里添加功能判断
//                NSMutableString *firstStr;
//                if (getEnglishLanguage()) {
//                    firstStr = [NSMutableString stringWithFormat:@"Chapter Task：%@",_model.CHAPTER_DESCRIBE];
//                }else{
//                    firstStr = [NSMutableString stringWithFormat:@"章节内容：%@",_model.CHAPTER_DESCRIBE];
//                }
//                
//                
//                
//                NSLog(@"%@",firstStr);
//                cell.textLabel.text = firstStr;
//            }else{
//                //这里添加功能判断
//                if (getEnglishLanguage()) {
//                    cell.textLabel.text = [NSString stringWithFormat:@"Chapter Task：%@",NoStr];
//                }else{
//                    cell.textLabel.text = [NSString stringWithFormat:@"章节内容：%@",NoStr];
//                }
//                
////                NSMutableArray * arr = [self componentsAllSeparatedByStringAndReturnAMutbleArr:_testLessionPlanString andString:@"#"];
////                NSString *str = @"章节内容：";
////                for (int i = 0;i<arr.count ;i++) {
////                    //                        if (i == arr.count-1) {
////                    //                            str = [NSString stringWithFormat:@"%@%@",str,[arr objectAtIndex:i]];
////                    //                        }else{
////                    str = [NSString stringWithFormat:@"%@\n%@",str,[arr objectAtIndex:i]];
////                    //                        }
////                    cell.textLabel.text = str;
////                    
////                }
//            }
//        }
//        
//        
//        if (indexPath.row == 2) {
//            if (_model.CHAPTER_TASK) {//练习题
//                //这里添加功能判断
//                NSMutableString *firstStr;
//                if (getEnglishLanguage()) {
//                    firstStr = [NSMutableString stringWithFormat:@"Exercise：%@",_model.CHAPTER_TASK];
//                }else{
//                    firstStr = [NSMutableString stringWithFormat:@"练习题：%@",_model.CHAPTER_TASK];
//                }
//                
//                
//                NSLog(@"%@",firstStr);
//                cell.textLabel.text = firstStr;
//            }else{
//                //这里添加功能判断
//                if (getEnglishLanguage()) {
//                    cell.textLabel.text = [NSString stringWithFormat:@"Exercise：%@",NoInformationStr];
//                }else{
//                    cell.textLabel.text = [NSString stringWithFormat:@"练习题：%@",NoInformationStr];
//                }
//                
//            }
//        }
        NSString *itemStr = [_ClassDetailArr objectAtIndex:indexPath.row];
        cell.textLabel.text = itemStr;

    }else if([getUserType() isEqualToString:UserISHPSStudent]){
    
            NSString *str1 = [KeyValuesClass dateGlinToFormate:self.model.startTime andFromate:@"yy-MM-dd HH:mm"];
            
            NSDateFormatter *formatter1 = [[NSDateFormatter alloc]init];
            [formatter1 setDateFormat:@"yy-MM-dd HH:mm"];
            
            NSString *dateLoca1 = [NSString stringWithFormat:@"%@",self.model.startTime];
            NSTimeInterval time1=[dateLoca1 doubleValue]/1000.0;
            NSDate *detaildate1=[NSDate dateWithTimeIntervalSince1970:time1];
            NSDate *dateBJTime1 = [[NSDate alloc]initWithTimeInterval:8*60*60 sinceDate:detaildate1];
            
            
            NSString *destDateString1 = [formatter1 stringFromDate:dateBJTime1];
            NSLog(@"error Time String is:%@",destDateString1);

            
            
            NSString *str2 = [KeyValuesClass dateGlinToFormate:self.model.endTime andFromate:@"yy-MM-dd HH:mm"];
            NSLog(@"str = %@",str2);
            NSDateFormatter *formatter2 = [[NSDateFormatter alloc]init];
            [formatter2 setDateFormat:@"yy-MM-dd HH:mm"];
            
            NSString *dateLoca2 = [NSString stringWithFormat:@"%@",self.model.endTime];
            NSTimeInterval time2=[dateLoca2 doubleValue]/1000.0;
            NSDate *detaildate2=[NSDate dateWithTimeIntervalSince1970:time2];
            NSDate *dateBJTime2 = [[NSDate alloc]initWithTimeInterval:8*60*60 sinceDate:detaildate2];
            
            
            NSString *destDateString2 = [formatter2 stringFromDate:dateBJTime2];
            NSLog(@"error Time String is:%@",destDateString2);
//            cell.textLabel.text = [NSString stringWithFormat:@"结束时间：%@", str2];
            
            NSArray *arrayOne = [str1 componentsSeparatedByString:@" "];
            NSArray *arrayTwo = [str2 componentsSeparatedByString:@" "];
            NSLog(@"arrayOne:%@ arrayTwo:%@",arrayOne,arrayTwo);
            
            
            if (indexPath.row == 0){
                cell.textLabel.text = [NSString stringWithFormat:@"上课时段：%@ - %@",arrayOne.lastObject,arrayTwo.lastObject];
                
                //        cell.textLabel.text = self.model.startTime;
            }
            if(indexPath.row == 1){
                cell.textLabel.text = [NSString stringWithFormat:@"上课日期：%@",arrayOne.firstObject];
                
            }
            
            if (indexPath.row == 2) {
                if (_model.CHAPTER_NAME) {
                    NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节: %@",_model.CHAPTER_NAME];;
                    
                    NSLog(@"%@",firstStr);
                    cell.textLabel.text = firstStr;
                }else{
                    cell.textLabel.text = @"章节：暂无信息";
                }
            }
            if (indexPath.row == 4) {
                cell.textLabel.numberOfLines = 0;
                cell.textLabel.lineBreakMode = NSLineBreakByCharWrapping;
                if (_model.CHAPTER_DESCRIBE) {
                    NSMutableString *firstStr = [NSMutableString stringWithFormat:@"章节内容: %@",_model.CHAPTER_DESCRIBE];
                    
                    
                    NSLog(@"%@",firstStr);
                    cell.textLabel.text = firstStr;
                }else{
                    cell.textLabel.text = @"章节任务：暂无信息";
//                    NSMutableArray * arr = [self componentsAllSeparatedByStringAndReturnAMutbleArr:_testLessionPlanString andString:@"#"];
//                    NSString *str = @"章节内容：";
//                    for (int i = 0;i<arr.count ;i++) {
////                        if (i == arr.count-1) {
////                            str = [NSString stringWithFormat:@"%@%@",str,[arr objectAtIndex:i]];
////                        }else{
//                            str = [NSString stringWithFormat:@"%@\n%@",str,[arr objectAtIndex:i]];
////                        }
//                        cell.textLabel.text = str;
                        
//                    }
                }
            }
            
            
            if (indexPath.row == 3) {
                if (_model.CHAPTER_TASK) {
                    NSMutableString *firstStr = [NSMutableString stringWithFormat:@"练习题: %@",_model.CHAPTER_TASK];;
                    
                    NSLog(@"%@",firstStr);
                    cell.textLabel.text = firstStr;
                }else{
                    cell.textLabel.text = @"练习题：暂无信息";
                }
            }

//        }
        
        
        
    }

    return cell;
}


- (BOOL)isBetweenFromHour:(NSInteger)fromHour toHour:(NSInteger)toHour {
    
    NSDate *dateFrom = [self getCustomDateWithHour:fromHour];
    NSDate *dateTo = [self getCustomDateWithHour:toHour];
    
    NSDate *currentDate = [NSDate date];
    if ([currentDate compare:dateFrom]==NSOrderedDescending && [currentDate compare:dateTo]==NSOrderedAscending) {
        // 当前时间在9点和10点之间
        return YES;
    }
    return NO;
}

- (NSDate *)getCustomDateWithHour:(NSInteger)hour {
    //获取当前时间
    
    NSDate *date = [self getInternetDate];
    NSLog(@"humanisdead:mismuth:%@",date);
    
    NSDate *currentDate = [NSDate date];
    NSCalendar *currentCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *currentComps = [[NSDateComponents alloc] init];
    
    NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    
    currentComps = [currentCalendar components:unitFlags fromDate:currentDate];
    
    //设置当天的某个点
    NSDateComponents *resultComps = [[NSDateComponents alloc] init];
    [resultComps setYear:[currentComps year]];
    [resultComps setMonth:[currentComps month]];
    [resultComps setDay:[currentComps day]];
    [resultComps setHour:hour];
    
    NSCalendar *resultCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    return [resultCalendar dateFromComponents:resultComps];
}

- (NSDate *)getInternetDate

{
    
    NSString *urlString = @"http://m.baidu.com";
    
    urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    
    // 实例化NSMutableURLRequest，并进行参数配置
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    
    [request setURL:[NSURL URLWithString: urlString]];
    
    [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
    
    [request setTimeoutInterval: 2];
    
    [request setHTTPShouldHandleCookies:FALSE];
    
    [request setHTTPMethod:@"GET"];
    
    
    
    NSHTTPURLResponse *response;
    
    [NSURLConnection sendSynchronousRequest:request
     
                          returningResponse:&response error:nil];
    
    
    
    // 处理返回的数据
    
    //    NSString *strReturn = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    
    
    
    NSLog(@"response is %@",response);
    
    NSString *date = [[response allHeaderFields] objectForKey:@"Date"];
    
    date = [date substringFromIndex:5];
    
    date = [date substringToIndex:[date length]-4];
    
    
    
    
    
    NSDateFormatter *dMatter = [[NSDateFormatter alloc] init];
    
    
    
    dMatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
    
    [dMatter setDateFormat:@"dd MMM yyyy HH:mm:ss"];
    NSDate *dateEight = [dMatter dateFromString:date];
//    NSDate *date = [NSDate date];
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate:dateEight];
    NSDate *localeDate = [dateEight dateByAddingTimeInterval: interval];
    NSLog(@"enddate=%@",localeDate);
    
    NSDate *netDate = [localeDate dateByAddingTimeInterval:60*60*8];
    
    return netDate;
    
}

#pragma - mark 将所有的某个字符串作为切割条件切割字符串并返回切割后的数组
- (NSMutableArray *)componentsAllSeparatedByStringAndReturnAMutbleArr:(NSString *)string andString:(NSString *)stringTwo{
    
    
    
    NSString *aaa = string;
    NSMutableArray *array = [NSMutableArray array];
    NSRange range = [aaa rangeOfString:@"#"];
//    while (1) {
        NSArray *arr = [aaa componentsSeparatedByString:stringTwo];
//        [array addObject:[arr firstObject]];
    array = [NSMutableArray arrayWithArray:arr];
//    [array removeObjectAtIndex:0];
//        aaa = [NSString stringWithFormat:@"%@",[arr lastObject]];
//        range = [aaa rangeOfString:@"#"];
//        if (range.location == NSNotFound) {
//            [array addObject:aaa];
//            break;
//        }
//    }
    _needMutArr = array;
    return array;
}


//- (UITableView *)myTableView{
//    
//    
//    
//    return myTableView;
//}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
